clear 

import excel ".../BaseDatos3.xls", sheet("Base Complementada") cellrange(A1:Z481) firstrow


log using "/.../panel_data_datos.smcl", text replace

* Entidad is a string variable and is not accepted by xtset.  We change it with Encode.
encode Entidad,gen(Entidad1)
drop Entidad
rename Entidad1 Entidad

* Set the Panel
xtset Entidad Year
sort Entidad Year



reg  BComercSecPrim BdeDSecPrim BComercSecSec BdeDSecSec BComercSecTer BdeDSecTer
asdoc estat vif, replace save(VIF)

*   Variable |       VIF       1/VIF  
*-------------+----------------------
*BComercSec~r |     48.28    0.020714
*BComercSec~c |     27.30    0.036627
*  BdeDSecSec |     25.22    0.039643
*  BdeDSecTer |     15.91    0.062854
* BdeDSecPrim |      1.11    0.899637
*-------------+----------------------
*    Mean VIF |     23.57



*****************************************************************************************************************
*****************************************************************************************************************

* Detecting Structural Breaks (unit roots vs Stationarity) 
* Harris-Tzavalis is better when N is large, but T is limited.

gen LogExport = log(Exportaciones/PIB)
xtunitroot ht LogExport

egen  logFDI = std(log(InverExtranjDir/PIB))
xtunitroot ht  InverExtranjDir
 
egen logGDPperCapita = std(log(PIBperCapita))
xtunitroot ht logGDPperCapita

egen logUnempl = std(log(IndiceDesempleo))
xtunitroot ht logUnempl


*****************************************************************************************************************
*****************************************************************************************************************
* Control for Financial Crises
gen dummyCrisis = Year == 2008 | Year == 2009

*****************************************************************************************************************
*****************************************************************************************************************
* Standardization of Variables
 
egen logExport = std(log(Exportaciones/PIB))

egen BComercSecPrimPc = std(log(BComercSecPrim/PIB))
egen  BdeDSecPrimPc = std(log(BdeDSecPrim/PIB))
egen  BComercSecSecPc = std(log(BComercSecSec/PIB)) 
egen BdeDSecSecPc = std(log(BdeDSecSec/PIB))   
egen BComercSecTerPc = std(log(BComercSecTer/PIB))
egen BdeDSecTerPc = std(log(BdeDSecTer/PIB))

egen Expenditure = std(log(Deuda/PIB))
egen Infrastructure = std(log(LongitudCarretra/PIB))
egen Education = std(log(Escolaridad))
egen LInflation = std(log(Inflation))

 
*****************************************************************************************************************
*****************************************************************************************************************
cls

* NOTE: to run the Hausman test, it is necessary to uncomment the pertinent commands.
* Furthermore, it is necessary to remove the robus option from the fixed effect regressions.

* EXPORT

* Version 1: only commercial credit
xtreg logExport Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BComercSecSecPc BComercSecTerPc if Year!=2020, fe robust
*estimates store fixedExportacionesPrivate 

*quietly xtreg logExport Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BComercSecSecPc BComercSecTerPc if Year!=2020, re
*estimates store randomExportacionesPrivate 
*hausman fixedExportacionesPrivate randomExportacionesPrivate, sigmamore

* Version 2: commercial and development credit
xtreg logExport  Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc if Year!=2020, fe robust
*estimates store fixedExportaciones 

*quietly xtreg logExport  Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc if Year!=2020, re
*estimates store randomExportaciones 

*hausman fixedExportaciones randomExportaciones, sigmamore


**************************************************************************************************************************
**************************************************************************************************************************
* FDI

* Version 1: only commercial credit
xtreg logFDI Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc  BComercSecSecPc BComercSecTerPc, fe robust
*estimates store fixedInverExtranjDirPrivate

*quietly xtreg logFDI Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc  BComercSecSecPc BComercSecTerPc, re
*estimates store randomInverExtranjDirPrivate
*hausman fixedInverExtranjDirPrivate randomInverExtranjDirPrivate

* Version 2: commercial and development credit
xtreg logFDI Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc,  fe robust
*estimates store fixedInverExtranjDir 

*quietly xtreg logFDI Expenditure Infrastructure Education LInflation dummyCrisis RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc, re
*estimates store randomInverExtranjDir

*hausman fixedInverExtranjDir randomInverExtranjDir


*****************************************************************************************************************
*****************************************************************************************************************
* GDP
gen logGDPperCapitan1 =  logGDPperCapita[_n-1]

* Version 1: only commercial credit

xtreg logGDPperCapita logGDPperCapitan1 logExport Expenditure Infrastructure Education LInflation dummyCrisis  RegionCentro CentroNorte Sur  BComercSecPrimPc BComercSecSecPc  BComercSecTerPc,  fe robust
*estimates store fixedLogGDPperCapitaPrivate 

*quietly xtreg logGDPperCapita logGDPperCapitan1 logExport Expenditure Infrastructure Education LInflation dummyCrisis  RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc, re 
*estimates store randLogGDPperCapitaPrivate 

*hausman fixedLogGDPperCapitaPrivate randLogGDPperCapitaPrivate, sigmamore


* Version 2: commercial and development credit

xtreg logGDPperCapita logGDPperCapitan1 logExport Expenditure Infrastructure Education LInflation dummyCrisis  RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc, fe robust
*estimates store fixedLogGDPperCapita

*quietly xtreg logGDPperCapita logGDPperCapitan1 logExport Expenditure Infrastructure Education LInflation dummyCrisis  RegionCentro CentroNorte Sur  BComercSecPrimPc BdeDSecPrimPc BComercSecSecPc BdeDSecSecPc BComercSecTerPc BdeDSecTerPc, re
*estimates store randLogGDPperCapita 

*hausman fixedLogGDPperCapita randLogGDPperCapita, sigmamore

**************************************************************************************************************************

capture log close
